CROSS_COMPILE ?= 
CC ?= gcc

model:=
name:=multiforward
bin:=$(name)
version:=1.0.0

INC = -Iinclude
CFLAGS ?= -g -std=gnu11
LDFLAGS ?=

REVISION ?= $(name)-$(version)-$(shell date +%Y%m%d.%H%M)

DIR_OBJS = obj
DIR_BIN = bin
DIR_SRC = src lib
 
dirs := $(DIR_BIN) $(DIR_OBJS)

src = $(foreach dir,$(DIR_SRC),$(wildcard $(dir)/*.c))
obj = $(foreach dir,$(DIR_SRC),$(patsubst $(dir)/%.c,%.o,$(src)))

obj := $(addprefix $(DIR_OBJS)/,$(filter %.o,$(obj)))
bin := $(addprefix $(DIR_BIN)/,$(bin))
 
all: $(dirs) $(bin)
 
$(dirs):
	@mkdir $@
 
$(bin):$(obj)
	@echo $(CFLAGS)
	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(INC) $(LIBS) -DREVISION=\"$(REVISION)\"
 
$(DIR_OBJS)/%.o:src/%.c
	$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS) $(INC) $(LIBS) -DREVISION=\"$(REVISION)\"

$(DIR_OBJS)/%.o:lib/%.c
	$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS) $(INC) $(LIBS)
 
clean:
	rm -rf $(bin) $(obj)
 
.PHONY:all clean
